﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;

namespace RIDA.Globals
{
   public static class VisualTreeHelperExtension
    {
       public static T GetParent<T>(this DependencyObject val) where T : DependencyObject
       {
           var p = VisualTreeHelper.GetParent(val);
           if (p == null)
               return default(T);
           while (p.GetType() != typeof(T))
           {
               p = VisualTreeHelper.GetParent(p);
               if (p == null)
                   return default(T);
           }

           return (T)p;

       }
    }
}
